<?php
class Vacancy extends AppModel {

     var $name = 'Vacancy';
     var $validate = array();
     
     function ValidateData(){
        $this->validate = array(
        						"Title" => array(
                                                    "rule1" => array(
                                                                        "rule" => "notEmpty",
                                                                        "message" => "Title is required",
                                                                        'last' => true
                                                                    ),
                                                  
                                                ),
                                                
                               "HourlyRate"=>array(
                                                	"rule1" => array(
                                                                        "rule" => "notEmpty",
                                                                        "message" => "Hourly Rate is required",
                                                                        'last' => true
                                                                    ),
                                                    "rule2" => array(
                                                                    "rule" => "numeric",
                                                                    "message" => "Hourly rate must is numeric",
                                                                     'last' => true
                                                                    ),
                                                ),
                                "MilageRateInPence"=>array(
                                                   "rule1" => array(
                                                                        "rule" => "notEmpty",
                                                                        "message" => "Milage rate in pence is required",
                                                                        'last' => true
                                                                    ),
                                                    "rule2" => array(
                                                                    "rule" => "numeric",
                                                                    "message" => "Milage rate in pence must is numeric",
                                                                    'last' => true
                                                                    ),
                                                ),
                                "MilageAllowanceAfterMiles"=>array(
                                                   "rule1" => array(
                                                                        "rule" => "notEmpty",
                                                                        "message" => "Milage allowance after miles is required",
                                                                        'last' => true
                                                                    ),
                                                    "rule1" => array(
                                                                    "rule" => "numeric",
                                                                    "message" => "Milage allowance after miles must is numeric",
                                                                    'last' => true
                                                                    ),
                                                ),
                            );
       if($this->validates($this->validate)) 
        return TRUE; 
       else 
        return FALSE;  
    } 
    
    function getListVacancy($the_i_PharmacyId)
    {
        return $this->find('all',array('conditions'=>array('Vacancy.Pharmacy_id'=>$the_i_PharmacyId)));
    }

    function getDetailVacancyByPharmacyIdAndVacancyId($the_i_VacancyId, $the_i_UserId)
    {
         return $shopStation = $this->find('first',array('joins' => array(
                                                                          array(
                                                                              'table' => 'users',
                                                                              'alias' => 'User',
                                                                              'type' => 'inner',
                                                                              'conditions'=> array('Vacancy.Pharmacy_id = User.id')
                                                                              )),'fields'=>array('Vacancy.*,User.Username'),'conditions'=>array('Vacancy.id'=>$the_i_VacancyId, 'Vacancy.Pharmacy_id' => $the_i_UserId)));
              
    }

    // Get list vacancy after 24h
	function getListVacancyLastest(){
	   $yesterday = strtotime('-1 days');
	   $yesterday = date('Y-m-d H:i:s', $yesterday); 
       return  $this->find('all',array('fields'=>array('Vacancy.id','Vacancy.Title','Vacancy.DateCreated'),
                                            'conditions'=>array(
                                                    'Vacancy.DateCreated > ' => $yesterday,
       												'Vacancy.DateRange <>' => '',
                                                    ),
                                            'order' => 'Vacancy.DateCreated DESC'
                                            )
        );
        
    }
	// Search by County
	function getListVacancyByCounty( $i_CountyId ){
       return  $this->find('all',array('conditions'=>array(
                                                    'Vacancy.County_id' => $i_CountyId,
                                                    ),
                                            'order' => 'Vacancy.DateCreated DESC'
                                            )
        );
        
    }
    
	function getVacancyById($i_VacancyId){
        
       return  $this->find('first',array( 'conditions'=>array(
                                                    'Vacancy.id'=>$i_VacancyId,
                                                    ),
                                            )
        );  
    }
    
 	function getListVacancyByStore($the_i_Store)
    {
        return $this->find('all',array('conditions'=>array('Vacancy.Store_id'=>$the_i_Store)));
    }

}
?>